﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HostAssistantCore
{
    public static class Extensions
    {
        /// <summary>
        /// 判断路径是否为根目录
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool EqualsRootPath(string path)
        {
            //c
            if (path.EqualsEx("c:\\") || path.EqualsEx("c:/"))
            {
                return true;
            }
            //d
            if (path.EqualsEx("d:\\") || path.EqualsEx("d:/"))
            {
                return true;
            }
            //e
            if (path.EqualsEx("e:\\") || path.EqualsEx("e:/"))
            {
                return true;
            }
            //f
            if (path.EqualsEx("f:\\") || path.EqualsEx("f:/"))
            {
                return true;
            }
            //g
            if (path.EqualsEx("g:\\") || path.EqualsEx("g:/"))
            {
                return true;
            }
            //return 
            return false;
        }

        /// <summary>
        /// 判断字符串是否相等
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        /// <returns></returns>
        public static bool EqualsEx(this string text1, string text2)
        {
            return string.Equals(text1, text2, StringComparison.CurrentCultureIgnoreCase);
        }

        /// <summary>
        /// 判断是否包含字符串
        /// </summary>
        /// <param name="text"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool ContainsEx(this string text, string value)
        {
            return text.IndexOf(value, StringComparison.CurrentCultureIgnoreCase) >= 0;
        }

        /// <summary>
        /// 判断是否以指定字符串开头
        /// </summary>
        /// <param name="text"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool StartWithEx(this string text, string value)
        {
            return text.StartsWith(value, StringComparison.CurrentCultureIgnoreCase);
        }

        /// <summary>
        /// 判断是否以指定字符串结尾
        /// </summary>
        /// <param name="text"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool EndWithEx(this string text, string value)
        {
            return text.EndsWith(value, StringComparison.CurrentCultureIgnoreCase);
        }

        /// <summary>
        /// 判断字符串是否空
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this string text)
        {
            return string.IsNullOrEmpty(text);
        }

    }
}
